package com.example.demo.entity;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * @Author : 叶荻风
 * @create : 2024/5/21 14:56
 */
public class PostProcessor  implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization   "+beanName);
        return BeanPostProcessor.super.postProcessBeforeInitialization(bean, beanName);
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization    "+beanName);

        if(bean instanceof Person){
            Person person = (Person) bean;
            person.setName("xwb");
            return BeanPostProcessor.super.postProcessAfterInitialization(person, beanName);
        }
        return bean;
    }

    public PostProcessor() {
    }
}
